#!/bin/bash

# 如果 rps90 计算失败，手动跑一遍

root="."
pythonI="./venv/bin/python3"

export PYTHONPATH=$(readlink -f "$root/src/trace_reconstructor/ports/python"):$PYTHONPATH

results_directory="$1"
load_levels="25,50,75,100"
app_names="bookinfo"

# 检查 results_directory 目录下是否有 PDF 文件，若有则备份
if ls "$results_directory"/*.pdf 1>/dev/null 2>&1; then
  backup_dir="${results_directory}/backup_$(date +%Y%m%d%H%M%S)"
  mkdir -p "$backup_dir"
  mv "$results_directory"/*.pdf "$backup_dir"
fi

$pythonI "$root/utils/plot_accuracy_vs_load_multiple_apps.py" $results_directory "test" "fig4a.pdf" $load_levels $app_names

$pythonI "$root/utils/plot_accuracy_vs_response_times_multiple_apps.py" $results_directory "test" "fig4b.pdf" $load_levels $app_names

$pythonI "$root/utils/plot_accuracy_vs_load_per_service_single_app.py" $results_directory "test" "fig4e.pdf" $load_levels $app_names

$pythonI "$root/utils/plot_accuracy_vs_load_avg_service_single_app.py" $results_directory "test" "fig4f.pdf" $load_levels $app_names

rmdir --ignore-fail-on-non-empty $results_directory
